package com.mediacloud.app.newsmodule.activity.microlive;

import android.graphics.drawable.GradientDrawable;
import androidx.annotation.CallSuper;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.TextView;
import com.mediacloud.app.assembly.views.GlideRoundImage;
import com.mediacloud.app.assembly.views.NetImageViewX;
import com.mediacloud.app.model.news.ArticleItem;
import com.mediacloud.app.model.utils.DefaultBgUtil;
import com.mediacloud.app.newsmodule.R;
import com.mediacloud.app.newsmodule.microlive.Lives;

import me.codeboy.android.aligntextview.CBAlignTextView;


/**
 */

public class MicroLiveDetailItemBaseViewHolder extends RecyclerView.ViewHolder
{
    public ArticleItem articleItem;
//    protected final View vertical_line;
//    private final View round_image;
    protected GlideRoundImage userHeader;
    protected TextView publishDate;
    protected TextView publishTitle;
    protected ViewGroup subLayout;
    protected ViewGroup videoXXX;
    protected NetImageViewX hamapiImage;
    protected View center_play;
    View appfacjnTop;

    @IMicroDetailDataObj.LiveType
    public int type;

    public final String TAG=getClass().getSimpleName();

    public MicroLiveDetailItemBaseViewHolder(View itemView, @IMicroDetailDataObj.LiveType int liveType)
    {
        super(itemView);
        itemView.setContentDescription(getClass().getName());
        this.type=liveType;
//        userHeader=itemView.findViewById(R.id.userHeader);
        appfacjnTop=itemView.findViewById(R.id.appfacjnTop);
//        vertical_line =itemView.findViewById(R.id.vertical_line);
//        round_image =itemView.findViewById(R.id.round_image);
        publishDate=itemView.findViewById(R.id.publishDate);
        publishDate.setTextColor(DefaultBgUtil.getTintColor(itemView.getContext()));
        publishTitle=itemView.findViewById(R.id.publishTitle);
        subLayout=itemView.findViewById(R.id.subLayout);
        videoXXX=itemView.findViewById(R.id.videoXXX);
        hamapiImage=itemView.findViewById(R.id.hamapiImage);
        center_play=itemView.findViewById(R.id.center_play);
        GradientDrawable gd = new GradientDrawable();
        gd.setColor(DefaultBgUtil.getTintColor(itemView.getContext()));
        gd.setCornerRadius(itemView.getResources().getDimension(R.dimen.dimen8));
//        round_image.setBackground(gd);
//        vertical_line.setBackgroundColor(itemView.getResources().getColor(R.color._color_jnsb));
    }

    @CallSuper
    public void setItemData(Lives data)
    {
        publishDate.setText(data.getPublishdate_format());
        if(publishTitle instanceof CBAlignTextView)
        {
            ((CBAlignTextView)publishTitle).reset();
            ((CBAlignTextView)publishTitle).setPunctuationConvert(true);
        }
        publishTitle.setText(data.getContent());
        if(TextUtils.isEmpty(data.getContent()))
        {
            publishTitle.setVisibility(View.GONE);
        }
        else
        {
            publishTitle.setVisibility(View.VISIBLE);
        }
        subLayout.setVisibility(View.GONE);
        if(1==data.getTopflag())
        {
            appfacjnTop.setVisibility(View.VISIBLE);
        }
        else
        {
            appfacjnTop.setVisibility(View.GONE);
        }
       if (getClass() == MicroLiveDetailItemBaseViewHolder.class)
            
        {
            subLayout.setVisibility(View.GONE);
        }
    }

    protected final void setSubLayoutSize()
    {
        final float p=887.0f/498.0f;
        subLayout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener()
        {
            @Override
            public boolean onPreDraw()
            {
                subLayout.getViewTreeObserver().removeOnPreDrawListener(this);
                if(subLayout.getVisibility()==View.GONE)
                    return true;
                int w=subLayout.getMeasuredWidth();
                int h= (int) (w/p);
                ViewGroup.LayoutParams layoutParams=subLayout.getLayoutParams();
                if(publishTitle.getVisibility()==View.GONE)
                {
                    subLayout.setPaddingRelative(subLayout.getPaddingStart(),itemView.getResources().getDimensionPixelOffset(R.dimen.dime_nine),subLayout.getPaddingEnd(),subLayout.getPaddingBottom());
                }
                else
                {
                    subLayout.setPaddingRelative(subLayout.getPaddingStart(),0,subLayout.getPaddingEnd(),subLayout.getPaddingBottom());
                }
                layoutParams.height=h;
                subLayout.setLayoutParams(layoutParams);
                return true;
            }
        });
    }
}